package com.bidepan.jdbc;

import com.alibaba.druid.pool.DruidDataSource;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestJdbc {
    //Druid连接池进行jdbc数据库连接的原生写法
    @Test
    public void demo1(){
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mysql://localhost:3306/spring6");
        dataSource.setUsername("root");
        dataSource.setPassword("hhp20040512");
        dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
    }

    //通过bean配置文件里面再引入外部properties文件进行依赖注入的方式实例化druidDataSource对象
    @Test
    public void demo2(){
        ApplicationContext context = new ClassPathXmlApplicationContext("bean-jdbc.xml");
        DruidDataSource dataSource = context.getBean("druidDataSource", DruidDataSource.class);
        System.out.println(dataSource.getUrl());
    }
}
